// 对象的混入，可以直接通过扩展运算符...,Object.assign()实现
// 通过原型的混入Object.assign()
// 通过闭包实现混入
/*
const canEat = {
  eat: function () { 
    console.log("eating");
  }
}

const canWalk = {
  walk: function () { 
    console.log("walking");
  }
}

class Person{
  constructor(name) {
    this.name = name;
  }
}

// const person = { ...canEat, ...canWalk };
// const person = Object.assign({}, canEat, canWalk);
// 通过原型混入
Object.assign(Person.prototype, canEat, canWalk);

const person = new Person("jack");
person.eat();
person.walk();
*/

// 通过闭包实现混入
function withEating(Class) {
  return class extends Class{
    eat() {
      console.log("eating");
    }
  }
}

function withWalking(Class) {
  return class extends Class{
    walk() {
      console.log("walking");
    }
  }
}

class Person{
  constructor(name) {
    this.name = name;
  }
}

const EatingAndWalkingPerson = withWalking(withEating(Person));

const person = new EatingAndWalkingPerson("john");
person.walk();
person.eat();